package com.qingcheng.controller;

import com.qingcheng.entity.Result;
import com.qingcheng.service.CartService;
import com.qingcheng.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/findCartList")
    public List<Map<String,Object>> findCartList(String username){
        List<Map<String, Object>> cartList = cartService.findCartList(username);
        return  cartList;
    }

    @PostMapping("/addItem")
    public Result addItem(String skuId, Integer num,String username){
        cartService.addItem(username,skuId,num);
        return new Result(200,"查询成功","");
    }

    @GetMapping("/deleteCart")
    public Result deleteCart(String username){
        cartService.deleteCart(username);
        return new Result();
    }

    @PostMapping("/updateChecked")
    public Result updateChecked(String skuId, boolean checked,String username) {
        cartService.updateChecked(username,skuId,checked);
        return new Result();
    }

    @GetMapping("/preferential")
    public Result preferential(String username){
        Map map = new HashMap();
        map.put("preferential",cartService.preferential(username));
        return new Result(200,"查询成功",map);
    }

    @GetMapping("/findNewOrderItemList")
    public List<Map<String,Object>> findNewOrderItemList(String username){
        return cartService.findNewOrderItemList(username);
    }
}
